<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateCommentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->unsignedInteger('post_id')->nullable()->comment('外键');
            $table->unsignedInteger('parent_id')->nullable()->comment('父评论id');
            $table->string('username')->comment('评论者用户名');
            $table->string('email')->comment('评论者邮箱');
            $table->text('content')->comment('评论内容');
            $table->timestamps();
        });
        $driverName = Schema::getConnection()->getDriverName();
        if ('mysql' === $driverName) {
            DB::update(<<<END
                ALTER TABLE `comment`
                ENGINE=InnoDB,
                DEFAULT CHARACTER SET=utf8,
                AUTO_INCREMENT=100;
END
            );
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

//        Schema::table('comments', function(Blueprint $table){
//            $table->dropForeign('comments_post_id_foreign');
//        });
        Schema::dropIfExists('comments');
    }
}
